import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class chessButton extends JButton {

	private int post;
	private int team;
	private String[] postList = { "King", "Queen", "Bishop", "Rook","Knight", "Pawn",
			 "null" };
	private String[] teamList = { "White", "Black" };
	private Image t;
	private int Size = 100;
	private Adrs adrs;
	private Style myBoard;
	private boolean canMove;

	// constract
	public chessButton(Style s, int x, int y, Adrs a) {
		this.myBoard = s;
		this.setAdrs(a);
		this.setBounds(x * this.Size, y * this.Size, 100, 100);
		this.setContentAreaFilled(false);
		this.setBackground(Color.CYAN);
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				chessButton cb = (chessButton) e.getSource();
				// System.out.println(cb.getAdrs());
				cb.myBoard.call(cb.getAdrs());
			}
		});
	}

	public chessButton(Style s, int post, int team, int x, int y, Adrs a) {
		this(s, x, y, a);
		this.post = post;
		this.team = team;
		//this.setIcon(new ImageIcon("image/" + this.teamList[this.team]
			//	+ this.postList[this.post] + ".png"));
	}

	public void setChess(int post, int team) {
		this.post = post;
		this.team = team;
		
		this.setIcon(new ImageIcon((Toolkit.getDefaultToolkit()).getImage(getClass().getResource(this.teamList[this.team]+ this.postList[this.post] + ".png"))));
		this.clrMovements();
	}

	public void setMovements() {
		this.setContentAreaFilled(true);
		this.setEnabled(true);
	}

	public void clrMovements() {
		this.setContentAreaFilled(false);
		this.setEnabled(false);
	}

	public void canMove() {
		this.canMove = true;
		this.setEnabled(true);
	}

	public void cantMove() {
		this.canMove = false;
		this.setEnabled(true);
	}

	public void noChess() {
		this.clrMovements();
		this.setEnabled(false);
		this.setIcon(null);
	}

	public int getPost() {
		return this.post;
	}

	public void setPostList(String[] s) {
		this.postList = s;
	}

	public void setTeamList(String[] s) {
		this.teamList = s;
	}

	public Adrs getAdrs() {
		return this.adrs;
	}

	public void setAdrs(Adrs a) {
		this.adrs = a;
	}

}
